<?php
require "../common/user_online.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>EbookAZ</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />	
	<?php require "../components/head.php" ?>
</head>
<body onload="MakeCurrentPage(1)">
<div id="container">
	<?php require "../components/user_menu.php" ?>
	<?php require "../components/user_header.php" ?>
	<div id="content">
		<?php require "../components/content_left.php"?>
		<div id="content_right">
		
		<div align='center'>
			<b style="color: blue">Cùng chia sẻ những ebook hay và độc đáo</b><br />
			<span>Nhập các thông tin sau để bắt đầu chia sẻ những ebook của bạn.</span><br />
			<hr width="600px" />
			
			<?php
				if(isset($_REQUEST["errorImg"]) || isset($_REQUEST["errorFile"]))
				{
					if($_REQUEST["errorImg"] == "other")
						echo "Ảnh minh họa bị lỗi. Vui lòng chọn ảnh khác";
					else if($_REQUEST["errorImg"] == "size")
						echo "Ảnh minh họa có kính thước quá lớn. Vui lòng chọn ảnh khác";
						
					if($_REQUEST["errorFile"] == "other")
						echo "File ebook bị lỗi. Vui lòng kiểm tra lại";
					else if($_REQUEST["errorFile"] == "size")
						echo "File ebook có kính thước quá lớn. Vui lòng kiểm tra lại";
						
					$title = $_SESSION["upload_title"];
					$type = $_SESSION["upload_type"];
					$field = $_SESSION["upload_field"];
					$category = $_SESSION["upload_category"];
					$author = $_SESSION["upload_author"];
					$publisher = $_SESSION["upload_publisher"];
					$pagenum = $_SESSION["upload_pagenum"];
					$desc = $_SESSION["upload_desc"];
				}
			?>
			<br /><br />
			<form id="formUpLoad" name="formUpload" action="uploadcontroller.php" method="post" enctype="multipart/form-data">		
				<table cellspacing="4" style="text-align:left">					
					<tr valign="top"> 
						<td><b>Tiêu đề</b></td>
						<td><input name="txtTitle" type="text" style="width: 400px" onblur="checkTitle()" value="<?php echo $title; ?>"></input><br><b id='bTitle'></b></td>
						<td><b style="color:#8C0000">*</b></td>
					</tr>
					<tr valign="top">
						<td><b>Tác giả</b></td>
						<td><input name="txtAuthor" type="text" style="width: 400px"  onblur="checkAuthor()" value="<?php echo $author; ?>"/><br><b id='bAuthor'></b></td>
						<td><b style="color:#8C0000">*</b></td>
					</tr>				
					<tr valign="top">
						<td><b>Nhà xuất bản</b></td>
						<td><input name="txtPublisher" type="text" style="width: 400px" onblur="checkPublisher()" value="<?php echo $publisher; ?>"/><br><b id='bPublisher'></b></td>
						<td>&nbsp;</td>
					</tr>
				
					<tr valign="top">
						<td><b>Danh mục</b></td>
						<td>
							<select name="cmbCat" onblur="checkCategory()" style='width:170px'>
								<option value="0">- - - Chọn - - -</option>
								<?php
								include "../common/db.inc";
								$conn = new mysqli($host, $username, $password, $dbname);	
								$conn->query("set names 'utf8'");
								
								$sql = "call sp_GetAllField()";
								$arrField = $conn->query($sql);
								while($field = $arrField->fetch_row())
								{							
									echo "<optgroup label='$field[1]'>";
									
									$conn = new mysqli($host, $username, $password, $dbname);	
									$conn->query("set names 'utf8'");
									
									$sql = "call sp_GetCategoryByField('$field[0]')";
									$arrCat = $conn->query($sql);
									while($cat = $arrCat->fetch_row())
									{							
										echo "<option value='$cat[0]'>$cat[1]</option>";
									}				
															
									echo "</option>";
								}
								?>	
							</select>
							<b id='bCat'></b>		
						</td>
						<td><b style="color:#8C0000">*</b></td>
					</tr>
					
					<tr valign="top">
						<td><b>Loại ebook</b></td>
						<td id="tdType">
							<?php
							require "../common/db.inc";
							$conn = new mysqli($host, $username, $password, $dbname);	
							$conn->query("set names 'utf8'");	
							
							echo "<select id='cmbType' name='cmbType' style='width:170px' value='$type'>";
								$strSQL = "call sp_GetAllEbookType()";
								$arrType = $conn->query($strSQL);
								while($row = $arrType->fetch_row())
								{							
									echo "<option value='$row[0]'>$row[1]</option>";
								}						
							echo "</select>";
							?>
						</td>
						<td><b style="color:#8C0000">*</b></td>
					</tr>			
					<tr valign="top">
						<td><b>Số trang</b></td>
						<td><input name="txtPageNum" type="text" size="5px"  onblur="checkPageNum()" value="<?php echo $pagenum; ?>"/><b id='bPageNum'></b></td>
						<td>&nbsp;</td>
					</tr>					
					<tr valign="top">
						<td><b>Mô tả</b></td>
						<td>
							<textarea name="txtDesc" cols="49" rows="10" onblur="checkDesc()" onkeyup="count()" onkeydown="checkcount()"><?php echo $desc; ?></textarea><br />
							<span id='idCount'>Tối đa 2000 ký tự</span><br />
							<b id='bDesc'></b>
						</td>
						<td><b style="color:#8C0000">*</b></td>
					</tr>
					<tr valign="top">
						<td><b>Ảnh minh họa</b></td>
						<td>
							<input type="file" id="fImage" size="55" name="fImage" onblur="checkImage()"/><br>
							<span>Chấp nhận file .gif, .jpg, .jpeg, .png (tối đa 3Mb)</span><br />
							<b id='bfImage'></b>							
						</td>
						<td>&nbsp;</td>
					</tr>
					<tr valign="top">
						<td><b>File tải lên</b></td>
						<td>
							<input type="file" id="fFile" size="55" name="fFile" onblur="checkFile()"/> <br>
							<span>Chấp nhận file .doc, .docx, .ppt, .pptx, .pdf, .prc, .txt, .chm</span><br />
							<span>Tối đa 20Mb</span><br />
							<b id='bfFile'></b>
						</td>
						<td><b style="color:#8C0000">*</b></td>			
					</tr>			
				</table>
				<br />
				<input type="button" name = "btnUpload" value="Upload" onClick="Upload()"/>
				<br /><br /><br />
			</form>
		</div>
		
		</div>
	</div>
	<?php require "../components/footer.php" ?>
</div>
</body>
</html>
